package com.chixing.controller;

import com.chixing.service.TravelSightsService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class TravelSightsController {
    @Autowired
    private TravelSightsService travelSightsService;

//    通过area获取该地区所有景点
    @GetMapping(value = {"travelSight/{sigthsArea}","travelSight/{sigthsArea}/page/{pageNum}"})
    @ResponseBody
    public ServerResponse getSightsByArea(@PathVariable("sigthsArea") String sigthsArea,@PathVariable(value = "pageNum",required = false) Integer pageNum){
//        ModelAndView mav = new ModelAndView();
        if (pageNum == null) {
            pageNum = 1;
        }
        ServerResponse serverResponse = travelSightsService.getBySightsArea(sigthsArea,pageNum);
//        mav.addObject("sigthsArea",sigthsArea);
//        mav.setViewName("travel/travel_list");
        return serverResponse;
    }

    @GetMapping("sights/sales/{id}")
    public ModelAndView getSightsToSales(@PathVariable("id")Integer id){
        ServerResponse response = travelSightsService.getSightsToSales(id);
        ModelAndView mav = new ModelAndView();
        mav.addObject("response",response);
        mav.setViewName("sales/sales");
        return mav;
    }

    public ModelAndView getSightsDetail(){
        ModelAndView mav = new ModelAndView();
        return mav;
    }

}
